package day2.assignments;
import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class MakePayment
 */
@WebServlet(urlPatterns = { "/MakePayment" }, name = "MakePayment")
public class MakePayment extends HttpServlet {
	private static final long serialVersionUID = 1L;

	private String customerCare;

	public void init(ServletConfig cfg) throws ServletException {
		super.init(cfg);
		ServletContext ctx = getServletContext();
		customerCare = ctx.getInitParameter("CustomerCare");
	}

	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		response.setContentType("text/html");
		PrintWriter out = response.getWriter();
		out.write("Thank you for making the payment of Rs."
				+ request.getAttribute("BillAmount") + " using "
				+ request.getAttribute("PaymentMode"));
		out.write("<br/>Customer Care: " + customerCare);
		out.close();
	}

}
